/**
 * Created by jean.h.ma on 05/03/2018.
 */

import React from 'react'
import {Provider} from "react-redux";
import Routes from './Routes'
import ApplicationSetting from '@codefree/badger/app/components/ApplicationSetting'
import Toast from '@codefree/badger/app/components/Toast'
import store from './store'
import {connect} from 'react-redux'

const ApplicationSettingWrapper = connect(({application}) => {
	return {
		setting: application.setting
	}
})(ApplicationSetting);

const ToastWrapper = connect(({toast}) => {
	return {
		messages: toast.message
	}
})(Toast);

export default class App extends React.Component {
	constructor(props) {
		super(props);
		//noinspection JSUnresolvedVariable
		this.state = {
			storeIsReady: true
		};
	}

	render() {
		if (!this.state.storeIsReady) {
			//TODO show loading for restore store
			return null;
		}
		return (
			<Provider store={store}>
				<span>
					<ApplicationSettingWrapper>
						<Routes/>
					</ApplicationSettingWrapper>
					<ToastWrapper/>
				</span>
			</Provider>
		);
	}
}